package beans;

import java.io.IOException;

import javax.faces.context.FacesContext;

public class BeanFunctions {
    
    public static final String SUCCESS = "success";

    public static void montrerDefaultInit(MainBean mainBean)
    {
        montrerXhtmlRedirect("pages/default", mainBean);
    }
    
    public static void montrerDefault(MainBean mainBean)
    {        
        montrerXhtmlRedirect("default", mainBean);
    }
    
    public static void montrerXhtmlRedirect(String xhtml, MainBean mainBean)
    {
        try
        {        
            FacesContext.getCurrentInstance().getExternalContext().redirect(xhtml + ".xhtml");            
        }
        catch(IOException e)
        {
            mainBean.setMessage(e.getMessage());
        }
    }
    
    public static void montrerXhtmlDispatch(String xhtml, MainBean mainBean)
    {
        try
        {
            //marche pas : PWC1232: Exceeded maximum depth for nested request dispatches: 20
            FacesContext.getCurrentInstance().getExternalContext().dispatch(xhtml + ".xhtml");
        }
        catch(IOException e)
        {
            mainBean.setMessage(e.getMessage());
        }
    }
    
}
